package com.albaba.designpattern.prototype.text_001;

import java.io.*;

/**
 * @author zx
 * @version 1.0
 * @description 序列化流实现深拷贝
 * @date 2025/2/19 22:07
 */
public class TextPrototype_002 {
    public static void main(String[] args) throws Exception{

        ConcretePrototype prototype = new ConcretePrototype();
        Person person = new Person("张三");
        prototype.setPerson(person);

        // 创建序列化输出流
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("a.txt"));

        // 将c1对象写到文件
        oos.writeObject(prototype);
        oos.close();
        // 创建对象的序列化对象输入流
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("a.txt"));
        ConcretePrototype prototype1 = (ConcretePrototype) ois.readObject();

        prototype1.getPerson().setName("李四");
        prototype1.show();
        prototype.show();
        System.out.println(prototype1.getPerson() == prototype.getPerson());

    }
}
